package com.fulihui.systemcore.biz.conv;

import com.fulihui.systemcore.dal.dataobj.Areas;
import com.fulihui.systemcore.dto.AreasDTO;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Willard.Hu on 2016/11/30 0030.
 */
public class AreasConv {

    public static Areas toDO(AreasDTO dto) {
        if (dto == null) {
            return null;
        }
        Areas db = new Areas();
        db.setCode(dto.getCode());
        db.setAreaName(dto.getAreaName());
        db.setParentCode(dto.getParentCode());
        db.setShortName(dto.getShortName());
        db.setLng(dto.getLng());
        db.setLat(dto.getLat());
        db.setLevel(dto.getLevel());
        db.setPosition(dto.getPosition());
        db.setSort(dto.getSort());
        return db;
    }

    public static AreasDTO toDTO(Areas db) {
        if (db == null) {
            return null;
        }
        AreasDTO dto = new AreasDTO();
        dto.setCode(db.getCode());
        dto.setAreaName(db.getAreaName());
        dto.setParentCode(db.getParentCode());
        dto.setShortName(db.getShortName());
        dto.setLng(db.getLng());
        dto.setLat(db.getLat());
        dto.setLevel(db.getLevel());
        dto.setPosition(db.getPosition());
        dto.setSort(db.getSort());
        return dto;
    }

    public static List<AreasDTO> toList(List<Areas> list) {
        if (CollectionUtils.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list.stream().map(AreasConv::toDTO).collect(Collectors.toList());
    }
}
